;; The first four lines of this file were added by Dracula.
;; They tell DrScheme that this is a Dracula Modular ACL2 program.
;; Leave these lines unchanged so that DrScheme can properly load this file.
#reader(planet "reader.rkt" ("cce" "dracula.plt") "modular" "lang")
(require "idatagenerators.lisp")
(require "mbmptree.lisp")
(require "mavltree.lisp")

; The module responsible for handling creating
; random data, including random bitmap files
; for use in testing
(module MDataGenerators
  (import Ibmptree)
  (import Iavltree)
  
  (include-book "doublecheck" :dir :teachpacks)
  (include-book "io-utilities" :dir :teachpacks)
  (include-book "list-utilities" :dir :teachpacks)
  
  ; Generates a random pixel (random RGB values).
  (defrandom random-pixel ()
    (let* ((r (random-between 0 255))
           (g (random-between 0 255))
           (b (random-between 0 255)))
      (list r g b)))
  
  ; Function that fills a bitmap tree with random pixels
  ; using the given dimensions.
  ;
  ; pre: tr - a bitmap tree
  ;      xcurr - the x index in the outer loop
  ;      ycurr  - the y index in the inner loop
  ;      height - the height of the image
  ;      width - the width of the image
  ;      pixels - the pixel data, (list (list r g b))
  ;
  ; post: a bitmap tree filled with the given pixel data
  (defun fill-bitmap (tr xcurr ycurr height width pixels)
    (if (< xcurr height)
          ; yes, is the current y index less than its max?
          (if (< ycurr width)
              ; yes, put in random pixel
              (fill-bitmap (insert-pixel tr (list xcurr ycurr (car pixels))) xcurr 
                           (+ ycurr 1) height width (cdr pixels))
              ; no, so reset y to 0 and increment x
              (fill-bitmap tr (+ xcurr 1) 0 height width pixels))
          ; x has extended past its max, so the recursion is done - return the new tree
          tr))
  
  ; Function that fills a bitmap tree with the given pixel
  ; using the given dimensions.
  ;
  ; pre: tr - a bitmap tree
  ;      xcurr - the x index in the outer loop
  ;      ycurr  - the y index in the inner loop
  ;      height - the height of the image
  ;      width - the width of the image
  ;      pixels - the pixel data, (list (list r g b))
  ;
  ; post: a bitmap tree filled with the given pixel data
  (defun fill-bitmap-with-pixel (tr xcurr ycurr height width pixel)
    (if (< xcurr height)
          ; yes, is the current y index less than its max?
          (if (< ycurr width)
              ; yes, put in random pixel
              (fill-bitmap-with-pixel (insert-pixel tr (list xcurr ycurr pixel)) xcurr 
                           (+ ycurr 1) height width pixel)
              ; no, so reset y to 0 and increment x
              (fill-bitmap-with-pixel tr (+ xcurr 1) 0 height width pixel))
          ; x has extended past its max, so the recursion is done - return the new tree
          tr))
  
 
  ; Random bitmap file, uses a static header with a 
  ; size of 25x25.
  (defrandom random-bitmap ()
    (let* ((header (list 66 77 54 12 0 0 0 0 0 0 54 0 0 
                         0 40 0 0 0 25 0 0 0 25 0 0 0 1 
                         0 24 0 0 0 0 0 0 12 0 0 0 0 0 
                         0 0 0 0 0 0 0 0 0 0 0 0 0))
           (width 25)
           (height 25)
           (pixels (random-list-of (random-pixel) :size (* width height)))
           (tr (insert-header (empty-bmp-tree) header)))
      (fill-bitmap tr 0 0 height width pixels)))
  
  (export IDataGenerators))